package com.web.controller;

import com.biz.service.RecommendService;
import com.biz.service.UserService;
import com.common.pojo.House;
import com.common.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class IndexController {

    @Resource
    private UserService userService;

    @Autowired
    private RecommendService recommendService;

    @RequestMapping("index")
    public String accountsRegister(ModelMap modelMap){
        List<House> houses =  recommendService.getLastest();
        modelMap.put("recomHouses", houses);
        return "/homepage/index";
    }


    @RequestMapping("")
    public String index(ModelMap modelMap){
        return "redirect:/index";
    }

    @RequestMapping("hello")
    public String hello(Model model){
        User u = userService.getUsers().get(0);
//        if (u!=null){
//            throw new IllegalArgumentException();
//        }
        model.addAttribute("user",u);
        return "hello";
    }

    @RequestMapping("/users")
    @ResponseBody
    public List<User> getUsers(){
        return userService.getUsers();
    }
}
